﻿@model WaiGaoQiaoWeb.Models.BringVM
@{
    ViewBag.Title = "InputIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("form", "validationEngine", "dp")
    @Html.Js("form", "validate", "unobtrusive", "inlinevalidation", "datepicker")
    <script type="text/javascript">
        $(document).ready(function () {
            $("form").makeValidationInline();

            $("#BringTime").datepicker({ picker: "<img class='picker' align='middle' src='../../Images/icons/s.gif' alt=''/>" });
            var mainheight = document.documentElement.clientHeight;
            var mainWidth = document.documentElement.clientWidth - 10;
            var gh = mainheight - 180;
            var option = {
                height: gh,
                width: mainWidth,
                url: '@Url.Action("GetBringList")',
                colModel: [
                     { display: 'ID', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                     { display: '物品名称', name: 'Article_ID', width: 120, sortable: false, hide: false, align: 'left' },
                      { display: '规格', name: 'Article_Unit', width: 120, sortable: false, hide: false, align: 'left' },
                     { display: '领取日期', name: 'BringTime', width: 120, sortable: false, hide: false, align: 'left' },
                     { display: '领取数量', name: 'BringCount', width: 80, sortable: false, hide: false, align: 'left' },
                     { display: '领取人工号', name: 'PersonNo', width: 80, sortable: false, hide: false, align: 'left' },
                     { display: '领取人姓名', name: 'PersonName', width: 100, sortable: false, hide: false, align: 'left' }
                //			         { display: '备注', name: 'Remark', width: 180, sortable: false, hide: false, align: 'left' },
               	],
                singleselected: false,
                sortname: "Sequence",
                sortorder: "asc",
                title: false,
                usepager: true,
                page: 1,
                rp: 10,
                rpoption: [10, 15, 20],
                showcheckbox: true,
                selectedonclick: true, //点击行是否选中
                rowbinddata: true
            };
            var grid = $("#postList").flexigrid(option);
            //保存
            $("#btnSave").click(function (event) {

                if (!$("#fmEdit").valid()) {
                    return false;
                }
                $('#fmEdit').ajaxSubmit(function (callback) {
                    if (callback) {
                        $(":input").each(function () {
                            if ($(this).attr("type") == "text" || $(this).attr("type") == "textarea") {
                                $(this).val("");
                            }
                        });
                        $("#Article_Unit").focus();
                    } //if
                }); //ajaxsubmit
            }); // end of btnSave

            //关闭
            $("#btnCancel").click(function (e) {
                $(":input").each(function () {
                    if ($(this).attr("type") == "text" || $(this).attr("type") == "textarea") {
                        $(this).val("");
                    }
                });
                $("#PersonNo").focus();
                CloseModelWindow(null, true);
            });
            $("#PersonNo").bind("blur", function () {
                $.post('@Url.Action("RtnPersonName", "PersonPostUnit")', { "personNo": $("#PersonNo").val() }, function (data) {
                    $("#PersonName").val(data.PersonName);
                    RtnArticle(data.Article_Unit, data.clu);
                    $("#postid").val(data.postid);
                });

            });
            function RtnArticle(ArticleName, ArticleId) {
                if (ArticleName != null && ArticleName != "") {
                    var charUnit = ArticleName.split(',');
                    var charUnitId = ArticleId.split(',');
                    if (charUnit.length > 0) {
                        $("#Article_ID").children("option").remove();
                        for (var i = 0; i < charUnitId.length - 1; i++) {
                            $("<option value=" + charUnitId[i] + ">" + charUnit[i] + " </option>").appendTo($("#Article_ID"));
                        }
                    } //if
                } //if

            }
            $("#Article_ID").bind("change", function () {
                if ($("#Article_ID").val() != 0) {
                    $.post('@Url.Action("RtnStorageInfoForUnit", "Storage")', { "Id": $("#Article_ID").val(), "random": Math.random() }, function (data) {
                        TtnUnitList(data.ArticleUnit, data.ArticleUnitId);
                    });


                }

            });
            function TtnUnitList(ArticleUnit, ArticleUnitId) {

                if (ArticleUnit != null && ArticleUnit != "") {
                    var charUnit = ArticleUnit.split(',');
                    var charUnitId = ArticleUnitId.split(',');
                    if (charUnit.length > 0) {
                        $("#Article_Unit").children("option").remove();
                        $("<option value='0' selected=selected>请选择... </option>").appendTo($("#Article_Unit"));
                        for (var i = 0; i < charUnitId.length; i++) {
                            $("<option value=" + charUnitId[i] + ">" + charUnit[i] + " </option>").appendTo($("#Article_Unit"));
                        }
                    } //if
                } //if
            } //end
            function refresh(perno) {
                showLoadingMsg("操作成功", { left: 300, top: 2 }, true, 3000);
                option.query = perno + "," + "";
                $("#postList").flexOptions(option).flexReload();
            }
            $("#btnDel").click(function () {
                if ($('.trSelected', grid).length == 0) {
                    showLoadingMsg("请选择要删除的行", { left: 300, top: 2 }, true, 3000);
                    return false;
                } else {
                    if (confirm("确定要删除吗?")) {
                        var rowcount = 0;
                        var items = $('.trSelected', grid);
                        for (var i = 0; i < items.length; i++) {
                            var id = items[i].id.substr(3);
                            $.ajax({
                                url: '@Url.Action("Delete")',
                                type: "POST",
                                data: { id: id },
                                async: false,
                                success: function (data) {
                                    if (data) {
                                        $("#postList").flexOptions(option).flexReload();
                                    }
                                },
                                error: function () {
                                }
                            });
                        } //for
                    }
                }
            });
        });
    </script>
}
@using (Html.BeginForm("SaveBring", "BringArticle", FormMethod.Post, new { id = "fmEdit" }))
{
    @Html.ValidationSummary(true)
    <div class="mainpanel">
        @Html.HiddenFor(model => model.ID)
        <table style="width: 94%;">
            <tr>
                <td colspan="4">
                    &nbsp;
                    <br />
                    <br />
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">用户工号
                </td>
                <td>@Html.TextBoxFor(model => model.PersonNo)
                    @Html.ValidationMessageFor(model => model.PersonNo)<span style="color: Red;">*</span>
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.PersonName)
                </td>
                <td>
                    @Html.TextBoxFor(model => model.PersonName)
                    @Html.ValidationMessageFor(model => model.PersonName)<span style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.Article_ID)
                </td>
                <td>
                    @Html.DropDownListFor(model => model.Article_ID, ViewBag.AID as IEnumerable<SelectListItem>, new { @style = "width:160px" })
                    @Html.ValidationMessageFor(model => model.Article_ID)<span style="color: Red;">*</span>
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.Article_Unit)
                </td>
                <td>
                    @Html.DropDownListFor(model => model.Article_Unit, ViewBag.UnitList as IEnumerable<SelectListItem>, new { @style = "width:160px" })
                    @Html.ValidationMessageFor(model => model.Article_Unit)<span style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.BringCount)
                </td>
                <td>
                @Html.TextBoxFor(model=>model.BringCount)
                    @Html.ValidationMessageFor(model => model.BringCount)<span style="color: Red;">*</span>
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.BringTime)
                </td>
                <td>
                    @Html.TextBoxFor(model => model.BringTime, new { @style="width:139px"})
                    @Html.ValidationMessageFor(model => model.BringTime)<span style="color: Red;">*</span>
                </td>
            </tr>
              <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.clu)
                </td>
                <td>
                    @Html.DropDownListFor(model => model.clu, ViewBag.clu as IEnumerable<SelectListItem>, new { @style = "width:160px" })
                    @Html.ValidationMessageFor(model => model.clu)<span style="color: Red;">*</span>
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.postid)
                </td>
                <td>
                    @Html.DropDownListFor(model => model.postid, ViewBag.postid as IEnumerable<SelectListItem>, new { @style = "width:160px" })
                    @Html.ValidationMessageFor(model => model.postid)<span style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                </td>
                <td colspan="2" align="right">
                    <a id="btnSave" class="button" href="javascript:void(0);"><span>保 存</span></a> <a
                        id="btnDel" class="button" href="javascript:void(0);"><span>删 除</span></a> <a id="btnCancel"
                            class="button" href="javascript:void(0);"><span>关 闭</span></a>
                </td>
            </tr>
        </table>
        <div style="overflow: scroll;">
            <table id="postList" style="display: none;">
            </table>
        </div>
    </div>
}
